package mianshi;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * TOOD
 *
 * @author long
 * @date 2020-08-17 17:23
 */
public class CallableThreadTest implements Callable<Integer> {
    int i=0;
    @Override
    public Integer call() throws Exception {
        for (;i<100;i++){
            System.out.println(Thread.currentThread().getName()+""+i);
        }
        return null;
    }
    public static void  main(String[] args){
        CallableThreadTest ctt=new CallableThreadTest();
        FutureTask<Integer> ft=new FutureTask<>(ctt);
        for (int i=0;i<100;i++){
            System.out.println(Thread.currentThread().getName()+"的循环变量i的值"+i);
            if (i==20){
                new Thread(ft,"有返回值的线程").start();
            }
        }
        try {
            System.out.println("子线程的返回值：" + ft.get());
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
